<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="培训名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入培训名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="省份" prop="province">
        <el-select v-model="queryParams.province" placeholder="请输入省份">
          <el-option
            v-for="item in addressData"
            :key="item.code"
            :label="item.name"
            :value="item.name"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['page:train:add']"
          >添加培训</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['page:train:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['page:train:remove']"
          >删除</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['page:train:export']"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="trainList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="id" align="center" prop="id" /> -->
      <el-table-column label="培训名称" align="center" prop="name" />
      <el-table-column label="培训类型 " align="center" prop="type" />
      <!-- <el-table-column label="比赛组别 " align="center" prop="groups" /> -->
      <el-table-column label="地址" align="center" width="180">
        <template slot-scope="scope">
          <span>{{
            scope.row.province +
            "/" +
            scope.row.city +
            "/" +
            (scope.row.address ? scope.row.address : "")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="报名起止报名时间" align="center" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.joinStartTime) }}</span
          ><br />
          <span>{{ parseTime(scope.row.joinEndTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="培训时间" align="center" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime) }}</span
          ><br />
          <span>{{ parseTime(scope.row.endTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="比赛状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <div slot="reference" class="name-wrapper">
              <el-tag
                v-show="scope.row.status === '未开始'"
                size="medium"
                type="danger"
                >{{ scope.row.status }}</el-tag
              >
              <el-tag
                v-show="scope.row.status === '报名中'"
                size="medium"
                type=""
                >{{ scope.row.status }}</el-tag
              >
              <el-tag
                v-show="scope.row.status === '报名结束'"
                size="medium"
                type="info"
                >{{ scope.row.status }}</el-tag
              >
              <el-tag
                v-show="scope.row.status === '待开始'"
                size="medium"
                type="warning"
                >{{ scope.row.status }}</el-tag
              >
              <el-tag
                v-show="scope.row.status === '进行中'"
                size="medium"
                type="success"
                >{{ scope.row.status }}</el-tag
              >
              <el-tag
                v-show="scope.row.status === '已完成'"
                size="medium"
                type="info"
                >{{ scope.row.status }}</el-tag
              >
            </div>
          </el-popover>
        </template>
      </el-table-column>

      <el-table-column
        label="单间价格/人"
        align="center"
        prop="singleRoomPrice"
      />
      <el-table-column
        label="标间价格/人"
        align="center"
        prop="standardRoomPrice"
      />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="300"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['page:train:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="addItem(scope.row)"
            >添加培训项目</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['page:train:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.rowsPerPage"
      @pagination="getList"
    />

    <!-- 添加或修改培训对话框 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      :visible.sync="open"
      width="1000px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="13">
            <el-form-item label="培训名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入培训名称" />
            </el-form-item>
          </el-col>
          <el-col :span="1">
            <el-form-item> </el-form-item>
          </el-col>
          <el-col :span="10">
            <!-- <el-form-item label="培训类型 " prop="type">
              <el-select v-model="form.type" placeholder="请选择培训类型">
                <el-option
                  v-for="dict in RaceMode"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.label"
                ></el-option>
              </el-select>
            </el-form-item> -->
            <el-form-item label="培训类型 " prop="type">
              <el-select
                v-model="form.type"
                filterable
                allow-create
                placeholder="请输入培训类型"
                ><el-option
                  v-for="dict in RaceMode"
                  :key="dict.id"
                  :label="dict.label"
                  :value="dict.label"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="比赛省份">
            <el-row>
              <el-select
                v-model="form.province"
                placeholder="请选择省"
                @change="changePro"
              >
                <el-option
                  v-for="item in addressData"
                  :key="item.code"
                  :label="item.name"
                  :value="item.name"
                >
                </el-option>
              </el-select>
              <el-select
                v-model="form.city"
                placeholder="请选择市"
                @change="changeCity"
              >
                <el-option
                  v-for="item in cityData"
                  :key="item.code"
                  :label="item.name"
                  :value="item.name"
                >
                </el-option>
              </el-select>
              <el-input
                placeholder="详细地址"
                v-model="form.address"
                style="width: 200px"
                clearable
              ></el-input>
            </el-row>
          </el-form-item>
        </el-row>

        <el-row>
          <el-form-item label="报名时间段">
            <el-date-picker
              v-model="form.joinStartTime"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择报名开始时间"
            >
            </el-date-picker>
            <span class="pickerSpan"> 至 </span>
            <el-date-picker
              v-model="form.joinEndTime"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="请选择报名结束时间"
            >
            </el-date-picker>
          </el-form-item>
        </el-row>

        <el-form-item label="拟定培训时间">
          <el-date-picker
            v-model="form.startTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择赛事开始时间"
          >
          </el-date-picker>
          <span class="pickerSpan"> 至 </span>
          <el-date-picker
            v-model="form.endTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择赛事结束时间"
          >
          </el-date-picker>
        </el-form-item>

        <el-row>
          <el-col :span="14">
            <el-form-item label="培训状态" prop="status">
              <el-radio-group v-model="form.status" size="small">
                <el-radio-button
                  v-for="item in playStatus"
                  :key="item.value"
                  :value="item.label"
                  :label="item.label"
                ></el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="4">
            <el-form-item> </el-form-item>
          </el-col> -->
          <el-col :span="8">
            <!-- <el-form-item label="培训组别 " prop="groups">
              <el-select
                v-model="form.groups"
                multiple
                filterable
                allow-create
                default-first-option
                placeholder="请输入培训组别"
              >
                <el-option
                  v-for="item in groups"
                  :key="item.id"
                  :label="item.label"
                  :value="item.label"
                >
                </el-option>
              </el-select>
            </el-form-item> -->
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="单间价格/人" prop="singleRoomPrice">
              <el-input
                v-model="form.singleRoomPrice"
                placeholder="请输入单间价格/人"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="标间价格/人" prop="standardRoomPrice">
              <el-input
                v-model="form.standardRoomPrice"
                placeholder="请输入标间价格/人"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 项目 -->
    <!-- 添加项目弹窗 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="projectTitle"
      :visible.sync="openItem"
      width="1000px"
      append-to-body
      class="scrollbar"
      @close="closedItem"
    >
      <el-scrollbar style="height: 100%">
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="itemHandleAdd"
              v-hasPermi="['game:project:add']"
              >新增</el-button
            >
          </el-col>
        </el-row>
        <el-table v-loading="Itemloading" :data="projectList">
          <!-- <el-table-column type="selection" width="55" align="center" /> -->
          <!-- <el-table-column label="id" align="center" prop="id" />
          <el-table-column
            label="比赛主键"
            align="center"
            prop="competitionId"
          /> -->
          <el-table-column label="项目" align="center" prop="name" />
          <el-table-column label="项目大类" align="center" prop="type" />
          <el-table-column label="最小人数" align="center" prop="sumMin" />
          <el-table-column label="最大人数" align="center" prop="sumMax" />
          <el-table-column label="报名费" align="center" prop="entryPrice" />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="itemHandleUpdate(scope.row)"
                v-hasPermi="['game:project:edit']"
                >修改</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="itemHandleDelete(scope.row)"
                v-hasPermi="['game:project:remove']"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-scrollbar>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
        <el-button @click="cancelProject">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改项目对话框 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="ItemTitle"
      :visible.sync="ItemOpen"
      width="500px"
      append-to-body
    >
      <el-form
        ref="itemForm"
        :model="itemForm"
        :rules="itemRules"
        label-width="80px"
      >
        <!-- <el-form-item label="比赛主键" prop="competitionId">
          <el-input
            v-model="itemForm.competitionId"
            placeholder="请输入比赛主键"
          />
        </el-form-item> -->
        <el-form-item label="项目大类">
          <el-select
            v-model.trim="itemForm.type"
            filterable
            allow-create
            placeholder="请选择项目大类"
            @change="changeType"
          >
            <el-option
              v-for="item in typeDic"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="具体项目" prop="name">
          <el-select
            v-model.trim="itemForm.name"
            filterable
            allow-create
            default-first-option
            placeholder="请选择具体项目"
          >
            <el-option
              v-for="item in projectDic"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="最小人数" prop="sumMin">
          <el-input v-model="itemForm.sumMin" placeholder="请输入最小人数" />
        </el-form-item>
        <el-form-item label="最大人数" prop="sumMax">
          <el-input v-model="itemForm.sumMax" placeholder="请输入最大人数" />
        </el-form-item>
        <el-form-item label="报名费" prop="entryPrice">
          <el-input v-model="itemForm.entryPrice" placeholder="请输入报名费" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="itemSubmititemForm">确 定</el-button>
        <el-button @click="itemCancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listTrain,
  getTrain,
  delTrain,
  addTrain,
  updateTrain,
  delTrains,
  listProject,
  getProject,
  delProject,
  delProjects,
  addProject,
  updateProject,
  getTypeDic,
  getProjectDic,
  getGroupsDic,
} from "@/api/page/train";
import address from "@/api/game/address.json";
export default {
  name: "Train",
  data() {
    return {
      typeDic: [],
      projectDic: [],
      // 表单参数
      itemForm: {},
      projectTitle: "",
      RaceMode: [
        {
          label: "培训",
          id: 0,
        },
        {
          label: "训练营",
          id: 1,
        },
      ],
      // 表单校验
      itemRules: {
        sumMin: [
          {
            pattern: /^[1-9]\d*$/,
            message: "必须为整数",
            trigger: "blur",
          },
        ],
        sumMax: [
          {
            pattern: /^[1-9]\d*$/,
            message: "必须为整数",
            trigger: "blur",
          },
        ],
        name: [
          { required: true, message: "培训项目不能为空", trigger: "blur" },
        ],
        type: [
          { required: true, message: "培训大类不能为空", trigger: "blur" },
        ],
      },
      groups: [],

      playStatus: [
        {
          value: 0,
          label: "未开始",
        },
        {
          value: 1,
          label: "报名中",
        },
        {
          value: 2,
          label: "报名结束",
        },
        {
          value: 3,
          label: "待开始",
        },
        {
          value: 4,
          label: "进行中",
        },
        {
          value: 5,
          label: "已完成",
        },
      ],
      //  省数据
      addressData: [],
      //  市数据
      cityData: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 培训表格数据
      trainList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        page: 1,
        rowsPerPage: 10,
        name: null,
        type: null,
        groups: null,
        province: null,
        city: null,
        joinStartTime: null,
        joinEndTime: null,
        startTime: null,
        endTime: null,
        address: null,
        singleRoomPrice: null,
        standardRoomPrice: null,
        // cost: null,
        // foodCost: null,
        status: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        sort: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "赛事名称不能为空", trigger: "blur" },
          {
            min: 2,
            max: 20,
            message: "赛事名称长度必须介于 2 和 20 之间",
            trigger: "blur",
          },
        ],
        type: [
          { required: true, message: "赛事类型不能为空", trigger: "blur" },
        ],
        groups: [{ required: true, message: "组别不能为空", trigger: "blur" }],
        province: [
          { required: true, message: "省份不能为空", trigger: "blur" },
        ],
        city: [{ required: true, message: "城市不能为空", trigger: "blur" }],
        address: [
          { required: true, message: "详细地址不能为空", trigger: "blur" },
        ],
        sumMin: [
          {
            pattern: /^[0-9]\d*$/,
            message: "必须为整数",
            trigger: "blur",
          },
        ],
        sumMax: [
          {
            pattern: /^[0-9]\d*$/,
            message: "必须为整数",
            trigger: "blur",
          },
        ],
        singleRoomPrice: [
          {
            pattern: /^[0-9]\d*$/,
            message: "必须为整数",
            trigger: "blur",
          },
        ],
        standardRoomPrice: [
          {
            pattern: /^[0-9]\d*$/,
            message: "必须为整数",
            trigger: "blur",
          },
        ],
        email: [
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"],
          },
        ],
        phone: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
      },
      projectList: [],
      // 遮罩层
      Itemloading: true,
      openItem: false,
      ItemTitle: "",
      ItemOpen: false,
      //培训id
      trainId: null,
      dataForm: {},
      nowPlayId: "",
    };
  },
  created() {
    // 省份数据初始化
    this.addressData = address;
    this.getList();
  },
  methods: {
    changeType(e) {
      this.itemForm.name = "";
      //过滤小类项目
      var a = this.typeDic.indexOf(e);
      if (a > -1) {
        getProjectDic(e).then((res) => {
          this.projectDic = res.data;
          console.log("小类" + res.data);
        });
      } else {
        this.projectDic = [];
      }
    },

    getItemTypeDic() {
      getTypeDic().then((res) => {
        this.typeDic = res.data;
        console.log(res.data);
      });
    },
    /** 提交按钮 */
    itemSubmititemForm() {
      this.projectDic = [];
      this.$refs["itemForm"].validate((valid) => {
        if (valid) {
          if (this.itemForm.id != null) {
            updateProject(this.itemForm).then((response) => {
              this.$modal.msgSuccess("修改成功");

              console.log("playId" + this.nowPlayId);
              this.itemGetList(this.nowPlayId);
              this.ItemOpen = false;
            });
          } else {
            this.itemForm.trainId = this.nowPlayId;
            addProject(this.itemForm).then((response) => {
              this.$modal.msgSuccess("新增成功");

              console.log("playId" + this.nowPlayId);
              this.itemGetList(this.nowPlayId);
              this.ItemOpen = false;
            });
          }
        }
      });
    },

    itemCancel() {
      this.projectDic = [];
      this.ItemOpen = false;
      this.itemReset();
    },

    //添加培训项目

    addItem(row) {
      this.nowPlayId = row.id;
      this.openItem = true;
      this.itemGetList(row.id);
    },

    /** 查询项目列表 */
    itemGetList(id) {
      this.Itemloading = true;
      listProject(id).then((response) => {
        this.projectList = response.data;
        // this.Itemtotal = response.data.totalCount;
        this.Itemloading = false;
      });
    },

    /** 新增按钮操作 */
    itemHandleAdd() {
      this.itemReset();
      this.getItemTypeDic();
      this.ItemOpen = true;
      this.ItemTitle = "添加项目";
      // this.itemForm.trainId = this.trainId;
    },
    // 表单重置
    itemReset() {
      this.itemForm = {
        id: null,
        trainId: null,
        name: null,
        type: null,
        sumMin: null,
        sumMax: null,
        entryPrice: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        sort: null,
      };
      this.resetForm("itemForm");
    },

    closedItem() {
      this.trainId = "";
      console.log("关闭dialog");
    },
    cancelProject() {
      this.openItem = false;
    },
    /** 修改按钮操作 */
    itemHandleUpdate(row) {
      this.itemReset();
      const id = row.id;
      this.getItemTypeDic();
      getProject(id).then((response) => {
        console.log(response.data);
        this.itemForm = response.data;
        this.ItemOpen = true;
        this.ItemTitle = "修改项目";
      });
    },

    itemHandleDelete(row) {
      if (row.id) {
        this.$modal
          .confirm('是否确认删除项目编号为"' + row.id + '"的数据项？')
          .then(function () {
            return delProject(row.id);
          })
          .then(() => {
            this.itemGetList(this.nowPlayId);
            this.$modal.msgSuccess("删除成功");
          })
          .catch(() => {});
      }
    },

    // 省份更改
    changePro(e) {
      // 省发生改变的时候 清空输入框市区街道的内容
      this.form.city = "";
      // 从省中过滤出市的数据
      this.cityData = this.addressData.filter((item) => {
        return item.name == e;
      })[0].children;
    },
    // 市更改
    changeCity(e) {},

    /** 查询培训列表 */
    getList() {
      this.loading = true;
      listTrain(this.queryParams).then((response) => {
        this.trainList = response.data.list;
        this.total = response.data.totalCount;
        this.loading = false;
        // this.trainList = [
        //   {
        //     name: "培训1",
        //     type: "和",
        //     groups: null,
        //     province: "山东省",
        //     city: "青岛市",
        //     joinStartTime: null,
        //     joinEndTime: null,
        //     startTime: null,
        //     endTime: null,
        //     cost: null,
        //     foodCost: null,
        //     status: "发布",
        //     createBy: null,
        //     createTime: null,
        //     updateBy: null,
        //     updateTime: null,
        //     sort: null,
        //   },
        // ];
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        type: null,
        groups: [],
        provinceCode: null,
        province: null,
        cityCode: null,
        city: null,
        joinStartTime: null,
        joinEndTime: null,
        startTime: null,
        endTime: null,
        // cost: null,
        // foodCost: null,
        address: null,
        singleRoomPrice: null,
        standardRoomPrice: null,
        status: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        sort: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      getGroupsDic().then((res) => {
        this.groups = res.data;
      });
      this.open = true;
      this.title = "添加培训";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getTrain(id).then((response) => {
        this.form = response.data;
        // this.form.groups = this.form.groups.split(",");
        this.open = true;
        this.title = "修改培训";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          // this.form.groups = this.form.groups.join(",");
          if (this.form.id != null) {
            updateTrain(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTrain(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      if (row.id) {
        const id = row.id;
        this.$modal
          .confirm('是否确认删除培训编号为"' + id + '"的数据项？')
          .then(function () {
            return delTrain(id);
          })
          .then(() => {
            this.getList();
            this.$modal.msgSuccess("删除成功");
          })
          .catch(() => {});
      } else {
        const ids = this.ids.join(",");
        this.$modal
          .confirm('是否确认删除培训编号为"' + ids + '"的数据项？')
          .then(function () {
            return delTrains(ids);
          })
          .then(() => {
            this.getList();
            this.$modal.msgSuccess("删除成功");
          })
          .catch(() => {});
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "page/train/export",
        {
          ...this.queryParams,
        },
        `train_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
